package com.origin.onlinesys.service.modules.interviewsys.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.Situations;
import com.origin.onlinesys.persistence.modules.interviewsys.SituationsMapper;
import com.origin.onlinesys.service.modules.interviewsys.ISituactionsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/1/22 0022.
 * 情况说明
 */
@Service
public class SituationsServiceImpl extends BaseService<Situations> implements ISituactionsService {
    /**
     * 插入情况说明
     * @param situations 情况说明对象
     * @return
     */
    public Situations insertSituations(Situations situations){
        String id = this.checkHave(situations.getName());
        situations.setState("1");
        if(id == null){
            situations.setId(this.save(situations)+"");
        }else{
            situations.setId(id);
            this.updateSituations(situations);
        }
        return situations;
    }

    /**
     * 删除情况说明
     * @param id
     * @return
     */
    public int deleteSituations(String id){
        Situations situations = new Situations();
        situations.setId(id);
        situations.setState("2");
        return update(situations);
    }

    /**
     * 修改情况说明
     * @param situations
     * @return
     */
    public int updateSituations(Situations situations){
        return this.update(situations);
    }

    /**
     * 查询所有情况说明
     * @return
     */
//    public List<Situations> selectAllSituations(){
//        return this.queryAll();
//    }

    /**
     * 根据条件查询情况说明
     * @param situations 情况说明对象
     * @return
     */
    public List<Situations> selectByWhere(Situations situations ){
        return this.queryByWhere(situations);
    }

    /**
     * 根据状态查询数据
     * @param state
     * @return
     */
    public List<Situations> selectByState(String state){
        return ((SituationsMapper)mapper).selectByState(state);
    }

    /**
     * 根据Id查询数据
     * @param id ID
     * @return
     */
    public Situations selectById(String id){
        Situations situ = new Situations();
        situ.setId(id);
        return this.queryByWhere(situ).get(0);
    }

    public String checkHave(String name) {
        return ((SituationsMapper)mapper).checkHave(name);
    }
}
